﻿using System;
using System.Drawing;

namespace MarioMapEditor
{
    class ObPipe : ObObject
    {
        public enum PIPE {Up = 30, Down, Left, Right, MidHor, MidVer};
        protected int WidthHor;
        protected int HeightHor;

        public ObPipe()
        {
            WidthHor    = 1;
            Info        = 100;
            HeightHor   = 2;
            Width       = 2;
            Height      = 1;
        }

        public ObPipe(PIPE nID)
        {
            ID          = (int)nID;
            Info        = 100;
            WidthHor    = 1;
            HeightHor   = 2;
            Width       = 2;
            Height      = 1;
        }

        public override bool SetID(int nID)
        {
            if (checkType(nID))
            {
                ID = nID;
                return true;
            }
            return false;
        }

        public override bool SetINFO(int nInfo)
        {
            Info = nInfo;
            return true;
        }

        public static bool checkType(int objectID)
        {
            if (Enum.IsDefined(typeof(PIPE), objectID))
            {
                return true;
            }
            return false;
        }

        public override int GetWidth()
        {
            if (ID == (int)PIPE.Down || ID == (int)PIPE.Up || ID == (int)PIPE.MidVer)
            {
                return Width;
            }
            if (ID == (int)PIPE.Left || ID == (int)PIPE.Right || ID == (int)PIPE.MidHor)
            {
                return WidthHor;
            }
            return 0;
        }

        public override int GetHeight()
        {
            if (ID == (int)PIPE.Down || ID == (int)PIPE.Up || ID == (int)PIPE.MidVer)
            {
                return Height;
            }
            if (ID == (int)PIPE.Left || ID == (int)PIPE.Right || ID == (int)PIPE.MidHor)
            {
                return HeightHor;
            }
            return 0;
        }

        public override Bitmap GetBitmap()
        {
            if (!checkType(ID))
            {
                return null;
            }
            Bitmap src;
            switch (ID)
            {
                case (int) PIPE.Up:
                    src = Properties.Resources.Top_Top;
                    return MainForm.ResizeImage(src, new Size(Width * MainForm.TileSize, Height * MainForm.TileSize));
                case (int) PIPE.Down:
                    src = Properties.Resources.Top_Bot;
                    return MainForm.ResizeImage(src, new Size(Width * MainForm.TileSize, Height * MainForm.TileSize));
                case (int) PIPE.MidVer:
                    src = Properties.Resources.Mid_Vertical;
                    return MainForm.ResizeImage(src, new Size(Width * MainForm.TileSize, Height * MainForm.TileSize));
                case (int) PIPE.Left:
                    src = Properties.Resources.Top_Left;
                    return MainForm.ResizeImage(src, new Size(WidthHor * MainForm.TileSize, HeightHor * MainForm.TileSize));
                case (int) PIPE.Right:
                    src = Properties.Resources.Top_Right;
                    return MainForm.ResizeImage(src, new Size(WidthHor * MainForm.TileSize, HeightHor * MainForm.TileSize));
                case (int) PIPE.MidHor:
                    src = Properties.Resources.Mid_Horizontal;
                    return MainForm.ResizeImage(src, new Size(WidthHor * MainForm.TileSize, HeightHor * MainForm.TileSize));
            }

            return null;
        }
    }
}
